<?php

class sfWidgetFormReCaptcha extends sfWidgetForm {
    protected $recaptcha;
    
    public function getReCaptcha()
    {
        if($this->recaptcha == null)
          $this->recaptcha = new reCaptcha();
        
        return $this->recaptcha;
    }
    
    public function __construct($options = array(), $attributes = array())
    {
        $this->recaptcha = new reCaptcha();
        $settings = $this->recaptcha->getSettings();
        $this->addOption('theme', $settings->getTheme());
        $this->addOption('custom_translations', $settings->getCustomTranslations());
        $this->addOption('lang', $settings->getLanguage());
        $this->addOption('tabindex', $settings->getTabIndex());
        $this->addOption('custom_theme_widget', $settings->getCustomThemeWidget());
        parent::__construct($options, $attributes);
    }
    
    protected function configure($options = array(), $attributes = array())
    {
        parent::configure($options, $attributes);
    }
    
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        $this->recaptcha->setTheme($this->getOption('theme'));
        $this->recaptcha->setLanguage($this->getOption('lang'));
        $this->recaptcha->setTabIndex($this->getOption('tabindex'));
        $this->recaptcha->setCustomTranslations($this->getOption('custom_translations'));
        $this->recaptcha->setCustomThemeWidget($this->getOption('custom_theme_widget'));
        return $this->recaptcha->getHTML();
    }
}